package com.yy.train.ticket.train.service.impl;

import com.yy.train.ticket.into.RunDate;
import com.yy.train.ticket.into.TrainNumber;
import com.yy.train.ticket.train.entity.TtTrainNumberEntity;
import com.yy.train.ticket.utils.LocalDateTimeUtils;
import com.yy.train.ticket.utils.R;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



import com.yy.train.ticket.train.dao.TtTrainRunDateDao;
import com.yy.train.ticket.train.entity.TtTrainRunDateEntity;
import com.yy.train.ticket.train.service.TtTrainRunDateService;

import javax.annotation.Resource;


@Service("ttTrainRunDateService")
public class TtTrainRunDateServiceImpl extends ServiceImpl<TtTrainRunDateDao, TtTrainRunDateEntity> implements TtTrainRunDateService {
@Resource
    TtTrainRunDateDao ttTrainRunDateDao;

    @Override
    public R saveRunDate(RunDate trainNumber) {
        List<String> runDates=trainNumber.getRunDates();
        String runTime=  trainNumber.getRunTime();
        Long numberId = trainNumber.getNumberId();
        LocalTime runTimeLocal= LocalDateTimeUtils.formatterToHH_mm_ss(runTime);
        List<TtTrainNumberEntity> list=new ArrayList<>();
        TtTrainRunDateEntity ttTrainNumber;
        for (String runDate:runDates
        ) {

            LocalDate runDateLocal= LocalDateTimeUtils.formatterToyyyy_MM_dd(runDate);

            ttTrainNumber=new TtTrainRunDateEntity();
            ttTrainNumber.setNumberId(numberId);
            ttTrainNumber.setRunDate(runDateLocal);
            ttTrainNumber.setRunTime(runTimeLocal);
         this.ttTrainRunDateDao.insert(ttTrainNumber);
        }
        return R.ok();
    }
}